﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Project.Server.Library;
using Microsoft.Office.Project.Server.Schema;

namespace Microsoft.Office.Project.EPMAuditing.Library
{
    class ProjectDataSetCompare
    {
        ProjectDataSet _oldProjectDataSet = null;
        ProjectDataSet _newProjectDataSet = null;


        public ProjectDataSetCompare()
        {

        }

        public ProjectDataSetCompare(ProjectDataSet oldProjectDataSet, ProjectDataSet newProjectDataSet)
        {
            _oldProjectDataSet = oldProjectDataSet;
            _newProjectDataSet = newProjectDataSet;
        }

        public ProjectDataSet OldProjectDataSet
        {
            set
            {
                _oldProjectDataSet = value;
            }
        }

        public ProjectDataSet NewProjectDataSet
        {
            set
            {
                _newProjectDataSet = value;
            }
        }
        public string Compare()
        {
            if ((_oldProjectDataSet == null) || (_newProjectDataSet == null))
                return string.Empty;

            StringBuilder compareResult = new StringBuilder(500);

            ProjectDataSet.ProjectRow oldProject = _oldProjectDataSet.Project[0];
            ProjectDataSet.ProjectRow newProject = _newProjectDataSet.Project[0];

            compareResult.Append(CompareHelper.Date("CREATED_DATE", oldProject.CREATED_DATE, newProject.CREATED_DATE));
            compareResult.Append(CompareHelper.Date("PROJ_INFO_CURRENT_DATE", oldProject.PROJ_INFO_CURRENT_DATE, newProject.PROJ_INFO_CURRENT_DATE));
            compareResult.Append(CompareHelper.Date("PROJ_INFO_FINISH_DATE", oldProject.PROJ_INFO_FINISH_DATE, newProject.PROJ_INFO_FINISH_DATE));
            compareResult.Append(CompareHelper.Bool("PROJ_INFO_SCHED_FROM", oldProject.PROJ_INFO_SCHED_FROM, newProject.PROJ_INFO_SCHED_FROM));
            compareResult.Append(CompareHelper.Date("PROJ_INFO_START_DATE", oldProject.PROJ_INFO_START_DATE, newProject.PROJ_INFO_START_DATE));
            compareResult.Append(CompareHelper.Date("PROJ_INFO_STATUS_DATE", oldProject.PROJ_INFO_STATUS_DATE, newProject.PROJ_INFO_STATUS_DATE));
            compareResult.Append(CompareHelper.Date("PROJ_LAST_SAVED", oldProject.PROJ_LAST_SAVED, newProject.PROJ_LAST_SAVED));
            compareResult.Append(CompareHelper.String("PROJ_NAME", oldProject.PROJ_NAME, newProject.PROJ_NAME));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_CALC_ACT_COSTS", oldProject.PROJ_OPT_CALC_ACT_COSTS, newProject.PROJ_OPT_CALC_ACT_COSTS));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_CRITICAL_SLACK_LIMIT", oldProject.PROJ_OPT_CRITICAL_SLACK_LIMIT, newProject.PROJ_OPT_CRITICAL_SLACK_LIMIT));
            compareResult.Append(CompareHelper.String("PROJ_OPT_CURRENCY_CODE", oldProject.PROJ_OPT_CURRENCY_CODE, newProject.PROJ_OPT_CURRENCY_CODE));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_CURRENCY_DIGITS", oldProject.PROJ_OPT_CURRENCY_DIGITS, newProject.PROJ_OPT_CURRENCY_DIGITS));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_CURRENCY_POSITION", oldProject.PROJ_OPT_CURRENCY_POSITION, newProject.PROJ_OPT_CURRENCY_POSITION));
            compareResult.Append(CompareHelper.String("PROJ_OPT_CURRENCY_SYMBOL", oldProject.PROJ_OPT_CURRENCY_SYMBOL, newProject.PROJ_OPT_CURRENCY_SYMBOL));
            compareResult.Append(CompareHelper.Short("PROJ_OPT_DAYS_PER_MONTH", oldProject.PROJ_OPT_DAYS_PER_MONTH, newProject.PROJ_OPT_DAYS_PER_MONTH));
            compareResult.Append(CompareHelper.Date("PROJ_OPT_DEF_FINISH_TIME", oldProject.PROJ_OPT_DEF_FINISH_TIME, newProject.PROJ_OPT_DEF_FINISH_TIME));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_DEF_FIX_COST_ACCRUAL", oldProject.PROJ_OPT_DEF_FIX_COST_ACCRUAL, newProject.PROJ_OPT_DEF_FIX_COST_ACCRUAL));
            compareResult.Append(CompareHelper.Double("PROJ_OPT_DEF_OVT_RATE", oldProject.PROJ_OPT_DEF_OVT_RATE, newProject.PROJ_OPT_DEF_OVT_RATE));
            compareResult.Append(CompareHelper.Date("PROJ_OPT_DEF_START_TIME", oldProject.PROJ_OPT_DEF_START_TIME, newProject.PROJ_OPT_DEF_START_TIME));
            compareResult.Append(CompareHelper.Double("PROJ_OPT_DEF_STD_RATE", oldProject.PROJ_OPT_DEF_STD_RATE, newProject.PROJ_OPT_DEF_STD_RATE));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_DEF_TASK_TYPE", oldProject.PROJ_OPT_DEF_TASK_TYPE, newProject.PROJ_OPT_DEF_TASK_TYPE));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_DUR_ENTRY_FMT", oldProject.PROJ_OPT_DUR_ENTRY_FMT, newProject.PROJ_OPT_DUR_ENTRY_FMT));
            compareResult.Append(CompareHelper.Short("PROJ_OPT_FY_START_MONTH", oldProject.PROJ_OPT_FY_START_MONTH, newProject.PROJ_OPT_FY_START_MONTH));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_FY_USE_START_YR", oldProject.PROJ_OPT_FY_USE_START_YR, newProject.PROJ_OPT_FY_USE_START_YR));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_HONOR_CONSTRAINTS", oldProject.PROJ_OPT_HONOR_CONSTRAINTS, newProject.PROJ_OPT_HONOR_CONSTRAINTS));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_MINUTES_PER_DAY", oldProject.PROJ_OPT_MINUTES_PER_DAY, newProject.PROJ_OPT_MINUTES_PER_DAY));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_MINUTES_PER_WEEK", oldProject.PROJ_OPT_MINUTES_PER_WEEK, newProject.PROJ_OPT_MINUTES_PER_WEEK));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_MOVE_ACTUAL_IF_LATER", oldProject.PROJ_OPT_MOVE_ACTUAL_IF_LATER, newProject.PROJ_OPT_MOVE_ACTUAL_IF_LATER));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_MOVE_ACTUAL_TO_STATUS", oldProject.PROJ_OPT_MOVE_ACTUAL_TO_STATUS, newProject.PROJ_OPT_MOVE_ACTUAL_TO_STATUS));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_MOVE_REMAINING_IF_EARLIER", oldProject.PROJ_OPT_MOVE_REMAINING_IF_EARLIER, newProject.PROJ_OPT_MOVE_REMAINING_IF_EARLIER));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_MOVE_REMAINING_TO_STATUS", oldProject.PROJ_OPT_MOVE_REMAINING_TO_STATUS, newProject.PROJ_OPT_MOVE_REMAINING_TO_STATUS));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_MULT_CRITICAL_PATHS", oldProject.PROJ_OPT_MULT_CRITICAL_PATHS, newProject.PROJ_OPT_MULT_CRITICAL_PATHS));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_NEW_TASK_EST", oldProject.PROJ_OPT_NEW_TASK_EST, newProject.PROJ_OPT_NEW_TASK_EST));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_NEW_TASKS_ARE_EFFORT_DRIVEN", oldProject.PROJ_OPT_NEW_TASKS_ARE_EFFORT_DRIVEN, newProject.PROJ_OPT_NEW_TASKS_ARE_EFFORT_DRIVEN));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_SHOW_EST_DUR", oldProject.PROJ_OPT_SHOW_EST_DUR, newProject.PROJ_OPT_SHOW_EST_DUR));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_SPLIT_IN_PROGRESS", oldProject.PROJ_OPT_SPLIT_IN_PROGRESS, newProject.PROJ_OPT_SPLIT_IN_PROGRESS));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_SPREAD_ACT_COSTS", oldProject.PROJ_OPT_SPREAD_ACT_COSTS, newProject.PROJ_OPT_SPREAD_ACT_COSTS));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_SPREAD_PCT_COMP", oldProject.PROJ_OPT_SPREAD_PCT_COMP, newProject.PROJ_OPT_SPREAD_PCT_COMP));
            compareResult.Append(CompareHelper.Bool("PROJ_OPT_TASK_UPDATES_RES", oldProject.PROJ_OPT_TASK_UPDATES_RES, newProject.PROJ_OPT_TASK_UPDATES_RES));
            compareResult.Append(CompareHelper.Short("PROJ_OPT_WEEK_START_DAY", oldProject.PROJ_OPT_WEEK_START_DAY, newProject.PROJ_OPT_WEEK_START_DAY));
            compareResult.Append(CompareHelper.Int("PROJ_OPT_WORK_ENTRY_FMT", oldProject.PROJ_OPT_WORK_ENTRY_FMT, newProject.PROJ_OPT_WORK_ENTRY_FMT));
            compareResult.Append(CompareHelper.String("PROJ_PROP_AUTHOR", oldProject.PROJ_PROP_AUTHOR, newProject.PROJ_PROP_AUTHOR));
            compareResult.Append(CompareHelper.String("PROJ_PROP_CATEGORY", oldProject.PROJ_PROP_CATEGORY, newProject.PROJ_PROP_CATEGORY));
            compareResult.Append(CompareHelper.String("PROJ_PROP_COMPANY", oldProject.PROJ_PROP_COMPANY, newProject.PROJ_PROP_COMPANY));
            compareResult.Append(CompareHelper.String("PROJ_PROP_KEYWORDS", oldProject.PROJ_PROP_KEYWORDS, newProject.PROJ_PROP_KEYWORDS));
            compareResult.Append(CompareHelper.String("PROJ_PROP_MANAGER", oldProject.PROJ_PROP_MANAGER, newProject.PROJ_PROP_MANAGER));
            compareResult.Append(CompareHelper.String("PROJ_PROP_SUBJECT", oldProject.PROJ_PROP_SUBJECT, newProject.PROJ_PROP_SUBJECT));
            compareResult.Append(CompareHelper.String("PROJ_PROP_TITLE", oldProject.PROJ_PROP_TITLE, newProject.PROJ_PROP_TITLE));
            compareResult.Append(CompareHelper.Bool("PROJ_PROP_COMPANY", oldProject.PROJ_PROTECTED_ACTUALS_SYNCH, newProject.PROJ_PROTECTED_ACTUALS_SYNCH));
            compareResult.Append(CompareHelper.Int("PROJ_TYPE", oldProject.PROJ_TYPE, newProject.PROJ_TYPE));

            if (compareResult.Length == 0)
                return string.Empty;
            else
            {
                compareResult.Insert(0, "<changes>");
                compareResult.Append("</changes>");
                return compareResult.ToString();
            }

        }


    }
}
